using System;
using NSubstitute;
using Phoenix.ActionResults;
using Phoenix.Controls;
using Phoenix.Frames;
using Phoenix.Framework;
using Phoenix.Lifetime;

namespace Phoenix.Tests
{
    public static class PhoenixObjectMother
    {
        public static ControllerActionContext CreateContext(
            ControllerAction controllerAction,
            INavigationFrame navigationFrame = null,
            IContentFrame contentFrame = null,
            ControllerActionParameter[] parameters = null)
        {
            var phoenixApplication = Substitute.For<IPhoenixHost>();
            var actionInvoker = Substitute.For<IActionInvoker>();
            var requestState = new RequestTransientStore();
            if (navigationFrame == null)
                navigationFrame = Substitute.For<INavigationFrame>();

            if (contentFrame == null)
                contentFrame = navigationFrame;
            phoenixApplication.ActionInvoker.Returns(actionInvoker);
            return new ControllerActionContext(controllerAction,
                                               navigationFrame,
                                               contentFrame,
                                               phoenixApplication,
                                               requestState,
                                               parameters ?? new ControllerActionParameter[0], InvokeOptions.None);
        }

        public static ActionResult CreateActionResult(ControllerActionContext context)
        {
            return Substitute.For<ActionResult>(context);
        }
    }
}
